import cv2  
import numpy as np  
  
# 读取图像  

def translate(img):
    # 获取图像的尺寸  
    (h, w) = img.shape[:2]  
    print("w//4:",w//4)
    print("h//4:",h//4)
    # 计算平移矩阵  
    M = np.float32([[1, 0, w//4], [0, 1, -h//4]])  
    
    # 进行图像平移  
    shifted = cv2.warpAffine(img, M, (w, h))  
    return shifted
    
img = cv2.imread('image/big_car.jpg')  
shifted = translate(img)

# 显示平移后的图像  
cv2.namedWindow('window', cv2.WINDOW_NORMAL)  
cv2.resizeWindow('window', 800, 600) 
cv2.namedWindow('window1', cv2.WINDOW_NORMAL)  
cv2.resizeWindow('window1', 800, 600) 


cv2.imshow('window', img)  
cv2.imshow('window1', shifted)  
cv2.waitKey(0)  
cv2.destroyAllWindows()